1. /* sifisadd.cpp by K.Tsuru */
  2. // function ID = 421 BRADIX
  3. /*************************************************
  4. SInteger class
  5. SInteger + unsigned short
  6. It is used in SInteger ConvToBin(const SLong& m);
  7. operator++
  8. result = m+s ( s < BRADIX)
  9. **************************************************/
  10. #ifndef SN_H
  11. #include "sn.h"
  12. #endif
  13. void IsAdd(const SInteger& m, fType s, SInteger& result){
  14. if(s >= BRADIX) m.SetError(m.OUT_OF_RANGE, "IsAdd", 421);
  15. result = m; // copy
  16. if(!s) return;
  17. // result == m
  18. if(m.Sign(421)<0){
  19. // m + s = -(|m|-s)
  20. result.SetSign(1); IsSub(result, s, result); result.SetSign(-1);
  21. return;
  22. }
  23. result.figure[0] += s; // result.figure[0] > 0
  24. if(result.figure[0] < BRADIX){ result.aTail = 0; return; }
  25. // normalize
  26. fType* rv = result.figure.Elements();
  27. fType u = rv[0] >> BRADIX_BITS; // u > 0
  28. rv[0] &= BRADIX1;
  29. register uint i = 0;
  30. while(u && i < m.aHead){
  31. i++;
  32. u += rv[i];
  33. rv[i] = u & BRADIX1;
  34. u >>= BRADIX_BITS;
  35. }
  36. if(u){ // for carray. i == m.aHead
  37. result.aHead++;
  38. result.Reserve(result.aHead);
  39. rv = result.figure.Elements();
  40. result.figure[result.aHead] = u;
  41. } else result.aHead = m.aHead;
  42. #ifndef NDEBUG
  43. result.figure(result.aHead);
  44. #endif
  45. i = 0;
  46. while(!rv[i]) i++;
  47. result.aTail = i;
  48. if( 2u*(result.aHead+1) <= result.figure.size() ) result.DoCutDown();
  49. }

sifisadd.cpp : last modifiled at 2017/03/13 14:31:59(1,373 bytes)
created at 2016/04/25 14:53:17
The creation time of this html file is 2017/10/25 11:09:45 (Wed Oct 25 11:09:45 2017).